package org.steven0lisa.typhoon.ui;

import net.jingkao.app.bean.annotation.InjectLayout;
import net.jingkao.app.bean.annotation.InjectView;
import net.jingkao.app.common.CommonWebChromeClient;
import net.jingkao.app.common.UIHelper;

import org.steven0lisa.typhoon.R;

import android.annotation.SuppressLint;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;


@InjectLayout(content=R.layout.about)
public class About extends BaseActivity {

	@InjectView(R.id.preference_about_webview)
	WebView vAboutContent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		initView();
		
		initAboutContent();
	}

	@SuppressLint("JavascriptInterface")
	private void initView() {
		vAboutContent.setOnLongClickListener(new UIHelper.ForbidWebViewLongClick());
		WebSettings setting = vAboutContent.getSettings();
		setting.setJavaScriptEnabled(true);
		vAboutContent.addJavascriptInterface(new Object(){
			public String getVersion() throws NameNotFoundException{
				PackageManager manager = About.this.getPackageManager();
				PackageInfo info = manager.getPackageInfo(About.this.getPackageName(), 0);
				return info.versionName;
			}
			public String getAppName(){
				return About.this.getString(R.string.app_name);
			}
		}, "application");
		
		vAboutContent.setWebChromeClient(new CommonWebChromeClient(this));
	}

	private void initAboutContent() {
		try {
			// 本地文件处理(如果文件名中有空格需要用+来替代)
			vAboutContent.loadUrl("file:///android_asset/about.html");
		} catch (Exception ex) {
			Log.e("About", "Cannot load about.html", ex);
			ex.printStackTrace();
		}
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}
	
}